package com.guangfeng.yql.comm.netty.chatroom.messageImpl;

import cn.hutool.json.JSONUtil;
import com.guangfeng.yql.comm.netty.annotation.AChatRoomMessage;
import com.guangfeng.yql.comm.netty.chatroom.ChatRoomMessage;
import com.guangfeng.yql.comm.netty.enumerate.ChatRoomMessageType;
import com.guangfeng.yql.comm.netty.util.ChatRoomUtil;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.http.websocketx.TextWebSocketFrame;
import org.springframework.stereotype.Component;

@AChatRoomMessage(ChatRoomMessageType.sendTextMessage)
@Component
public class SendTextChatRoom extends ChatRoomMessage {

    @Override
    public void tactics(ChannelHandlerContext ctx, TextWebSocketFrame msg) {
        Object parse = JSONUtil.parse(msg.text()).getByPath("msg");
        if (parse == null) {
            return;
        }

        ChatRoomUtil.sendText(ctx.channel(), parse.toString());
    }
}
